package com.sdy.usercenter.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdy.usercenter.biz.model.SysLog;
import com.sdy.usercenter.biz.mapper.SysLogMapper;
import com.sdy.usercenter.biz.model.SysUserDept;
import com.sdy.usercenter.biz.service.SysLogService;
import com.sdy.mvc.service.impl.BaseServiceImpl;
import com.sdy.usercenter.biz.service.SysUserDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzq
 * @since 2019-06-14
 */
@Slf4j
@Service
public class SysLogServiceImpl extends BaseServiceImpl<SysLog> implements SysLogService {
    @Autowired
    private SysLogMapper sysLogMapper;
    @Autowired
    private SysUserDeptService sysUserDeptService;

    @Override
    public void logCommonInfo(Integer type, Integer opUserId, Date opTime, String ip, String content) {
        SysLog log = new SysLog()
                .setUserId(opUserId)
                .setOpTime(opTime)
                .setCreateTime(new Date())
                .setContent(content)
                .setIp(ip)
                .setType(type);
        List<SysUserDept> l = sysUserDeptService.list(new QueryWrapper<SysUserDept>().eq("user_id", opUserId).eq("admin", 2));
        if (!l.isEmpty()) {
            log.setDeptId(l.get(0).getDeptId());
        }
        save(log);
    }
}
